/**
 * 
 */
package cn.gov.msa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;

import cn.gov.msa.dao.DeclareItemMapper;
import cn.gov.msa.dao.FileMapper;
import cn.gov.msa.dao.ServiceGuideMapper;
import cn.gov.msa.model.DeclareItem;
import cn.gov.msa.model.Flow;
import cn.gov.msa.model.ServiceGuide;
import cn.gov.msa.service.DeclareItemService;
import cn.gov.msa.service.GuideService;

/**
 * @Title: GuideServiceImpl.java
 * @Package cn.gov.msa.service.impl
 * @Description: TODO(用一句话描述该文件做什么)
 * @author 何宇江
 * @date 2018年3月5日 下午5:16:34
 */
public class GuideServiceImpl implements GuideService {

	@Autowired
	ServiceGuideMapper serviceGuideMapper;
	@Autowired
	DeclareItemMapper declareItemMapper;
	

	@Override
	public List<ServiceGuide> selectData(ServiceGuide serviceGuide) throws Exception {
		
        //读取数据库信息
	    List<ServiceGuide> guideList = serviceGuideMapper.selectData(serviceGuide);

	    return guideList;
	}
	
	@Transactional
	@Override
	public boolean saveData(ServiceGuide serviceGuide) throws Exception {

		boolean save = false;
		int i = 0;

		if(serviceGuide.getSgid() == null || "".equals(serviceGuide.getSgid())){
			i = serviceGuideMapper.insert(serviceGuide);
			
			String itemno = serviceGuide.getItemno();
			DeclareItem declareItem = declareItemMapper.selectByPrimaryKey(itemno);
			declareItem.setGuideid(serviceGuide.getSgid());
	
			int j = declareItemMapper.updateByPrimaryKey(declareItem);
			
		}
		else{
			i = serviceGuideMapper.updateByPrimaryKey(serviceGuide);
		}
		save = i > 0 ? true : false;
		

		return save;
	}

}
